﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP30.ViewModels
{
    public class ST05DeviceManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST05DeviceManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;


            ST5PressureSetValue = TurntablePCToPLC_Global.nPressSetValue;

            ST5PressureCheckValue = TurntablePCToPLC_Global.nCheckValue;

            ST5PressureCheckOffset = TurntablePCToPLC_Global.nCheckOffset;

            TurntablePCToPLC_Global.WeldONBT = true;
            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();

        }

        private void OnTick(object? sender, EventArgs e)
        {
            ST5PressureCurrentValue = TurntablePLCToPC_Global.ST5WeldPress;
        }


        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST05");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST05View, param);
        }


        private DelegateCommand _ST5ManualDownCmd;
        public DelegateCommand ST5ManualDownCmd =>
            _ST5ManualDownCmd ?? (_ST5ManualDownCmd = new DelegateCommand(ExecuteST5ManualDownCmd));

        void ExecuteST5ManualDownCmd()
        {
            TurntablePCToPLC_Global.WeldMaualMode = true;
        }

        private DelegateCommand _ST5ManualUpCmd;
        public DelegateCommand ST5ManualUpCmd =>
            _ST5ManualUpCmd ?? (_ST5ManualUpCmd = new DelegateCommand(ExecuteST5ManualUpCmd));

        void ExecuteST5ManualUpCmd()
        {
            TurntablePCToPLC_Global.WeldMaualMode = false;

        }

        private DelegateCommand _ST5TestDownCmd;
        public DelegateCommand ST5TestDownCmd =>
            _ST5TestDownCmd ?? (_ST5TestDownCmd = new DelegateCommand(ExecuteST5TestDownCmd));

        void ExecuteST5TestDownCmd()
        {
            TurntablePCToPLC_Global.WeldTextBT = true;
        }

        private DelegateCommand _ST5TestUpCmd;
        public DelegateCommand ST5TestUpCmd =>
            _ST5TestUpCmd ?? (_ST5TestUpCmd = new DelegateCommand(ExecuteST5TestUpCmd));

        void ExecuteST5TestUpCmd()
        {
            TurntablePCToPLC_Global.WeldTextBT = false;

        }

        private DelegateCommand _ST5OnCmd;
        public DelegateCommand ST5OnCmd =>
            _ST5OnCmd ?? (_ST5OnCmd = new DelegateCommand(ExecuteST5OnCmd));

        void ExecuteST5OnCmd()
        {
            TurntablePCToPLC_Global.WeldONBT = true;
        }

        private DelegateCommand _ST5OffCmd;
        public DelegateCommand ST5OffCmd =>
            _ST5OffCmd ?? (_ST5OffCmd = new DelegateCommand(ExecuteST5OffCmd));

        void ExecuteST5OffCmd()
        {
            TurntablePCToPLC_Global.WeldONBT = false;

        }


        private DelegateCommand _ST5RedLightOnCmd;
        public DelegateCommand ST5RedLightOnCmd =>
            _ST5RedLightOnCmd ?? (_ST5RedLightOnCmd = new DelegateCommand(ExecuteST5RedLightOnCmd));

        void ExecuteST5RedLightOnCmd()
        {
            TurntablePCToPLC_Global.bIn6 = true;
        }

        private DelegateCommand _ST5RedLightOffCmd;
        public DelegateCommand ST5RedLightOffCmd =>
            _ST5RedLightOffCmd ?? (_ST5RedLightOffCmd = new DelegateCommand(ExecuteST5RedLightOffCmd));

        void ExecuteST5RedLightOffCmd()
        {
            TurntablePCToPLC_Global.bIn6 = false;
        }


         private DelegateCommand _ST5ManualTestCmd;
        public DelegateCommand ST5ManualTestCmd =>
            _ST5ManualTestCmd ?? (_ST5ManualTestCmd = new DelegateCommand(ExecuteST5ManualTestCmd));

        void ExecuteST5ManualTestCmd()
        {
            TurntablePCToPLC_Global.bIn7 = true;
        }

        private DelegateCommand _UnST5ManualTestCmd;
        public DelegateCommand UnST5ManualTestCmd =>
            _UnST5ManualTestCmd ?? (_UnST5ManualTestCmd = new DelegateCommand(ExecuteUnST5ManualTestCmd));

        void ExecuteUnST5ManualTestCmd()
        {
            TurntablePCToPLC_Global.bIn7= false;
        }

        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {

                case "ST5PressureSetValue":
                    TurntablePCToPLC_Global.nPressSetValue = ST5PressureSetValue;
                    break;

                case "ST5PressureCheckValue":
                    TurntablePCToPLC_Global.nCheckValue = ST5PressureCheckValue;
                    break;

                case "ST5PressureCheckOffset":
                    TurntablePCToPLC_Global.nCheckOffset = ST5PressureCheckOffset;
                    break;
                default:
                    break;
            }
        }
        #endregion



        #region 属性

        private float _ST5PressureCurrentValue;
        public float ST5PressureCurrentValue
        {
            get { return _ST5PressureCurrentValue; }
            set { SetProperty(ref _ST5PressureCurrentValue, value); }
        }

        private float _ST5PressureSetValue;
        public float ST5PressureSetValue
        {
            get { return _ST5PressureSetValue; }
            set { SetProperty(ref _ST5PressureSetValue, value); }
        }

        private float _ST5PressureCheckValue;
        public float ST5PressureCheckValue
        {
            get { return _ST5PressureCheckValue; }
            set { SetProperty(ref _ST5PressureCheckValue, value); }
        }

        private float _ST5PressureCheckOffset;
        public float ST5PressureCheckOffset
        {
            get { return _ST5PressureCheckOffset; }
            set { SetProperty(ref _ST5PressureCheckOffset, value); }
        }
        #endregion
    }
}
